package qx.hyj.demos.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import qx.hyj.demos.entity.Book;
import qx.hyj.demos.entity.Ubjl;
import qx.hyj.demos.entity.User;
import qx.hyj.demos.enums.ErrorCode;

import java.util.List;

@Repository
public interface BookMapper {
    @Select("select * from book where title = #{bookName}")
    Book getIdByName(String bookName);

    @Insert("insert into ubjl (rid, sid,borrowTime) values (#{userId}, #{bookId},#{borrowTime})")
    int borrowBook(@Param("userId") Integer userId, @Param("bookId") Integer bookId, @Param("borrowTime") String borrowTime);

    @Delete("delete from ubjl where rid = #{userId} and sid = #{bookId}")
    Integer returnBook(@Param("userId") Integer userId, @Param("bookId") Integer bookId);

    @Update("update book set status = #{status} where id = #{id}")
    Integer updateBookStatus(@Param("id") Integer id, @Param("status") ErrorCode status);

    @Update("update book set stock = #{stock} where id = #{id}")
    Integer updateBookStock(@Param("id") Integer id, @Param("stock") Integer stock);

    @Select("select * from ubjl where rid = #{userId} and sid = #{bookId}")
    Ubjl getUsjl(@Param("userId") Integer userId, @Param("bookId") Integer bookId);

    @Select("select sid,borrowTime from ubjl where rid = #{rid}")
    List<Ubjl> getbookJl(Integer rid);

    @Select("select * from book where id = #{id}")
    Book getbookAll(Integer id);

}

